{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "#这个lgb只放re和cnt，不放所有的类别信息\n",
    "\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "import seaborn as sbn\n",
    "import pandas as pd\n",
    "import lightgbm as lgb\n",
    "import datetime \n",
    "import math \n",
    "import gc\n",
    "import os"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "#输入文件\n",
    "DATA_PATH = os.path.join(os.getcwd(),'data','simply_id','input')\n",
    "NEW_TRAIN  =  os.path.join(DATA_PATH,'new_train.csv')\n",
    "NEW_TEST = os.path.join(DATA_PATH,'new_test.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "train = pd.read_csv(NEW_TRAIN)\n",
    "test = pd.read_csv(NEW_TEST)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "train.drop(['msno', 'song_id', 'op_type', 'city', 'registered_via',\n",
    "       'registration_init_time', 'song_length', 'song_year', 'first_genre_id',\n",
    "       'artist_name_id', 'lyricist_id', 'language_id'],axis = 1,inplace = True)\n",
    "test.drop(['msno', 'song_id', 'op_type', 'city', 'registered_via',\n",
    "       'registration_init_time', 'song_length', 'song_year', 'first_genre_id',\n",
    "       'artist_name_id', 'lyricist_id', 'language_id'],axis = 1,inplace = True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "for col in train.columns:\n",
    "    if train[col].dtype == object:\n",
    "        train[col] = train[col].astype('category')\n",
    "for col in test.columns:\n",
    "    if test[col].dtype == object:\n",
    "        test[col] = test[col].astype('category')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "X_train = train.drop(['target'], axis=1).values\n",
    "y_train = train['target'].values\n",
    "X_test = test.drop(['target'], axis=1).values\n",
    "y_test = test['target'].values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "d_train_final = lgb.Dataset(X_train, y_train)\n",
    "watchlist_final = lgb.Dataset(X_test, y_test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "params = {\n",
    "        'objective': 'binary',\n",
    "        'metric': 'binary_logloss',\n",
    "        'boosting': 'gbdt',\n",
    "        'learning_rate': 0.1,\n",
    "        'verbose': 0,\n",
    "        'num_leaves': 108,\n",
    "        'bagging_fraction': 0.9,\n",
    "        'bagging_freq': 2,\n",
    "        'bagging_seed': 3,\n",
    "        'feature_fraction': 0.8,\n",
    "        'feature_fraction_seed': 2,\n",
    "        'max_bin': 256,\n",
    "        'max_depth': 30,\n",
    "        'num_rounds': 500,\n",
    "        'metric' : 'auc',\n",
    "        'using_missing' : False,\n",
    "        'is_unbalance' : True\n",
    "        #'sigmoid' : 1.0 ,\n",
    "        #'train_metric' : True\n",
    "    }"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "D:\\Users\\10100\\Anaconda3\\lib\\site-packages\\lightgbm\\engine.py:99: UserWarning: Found `num_rounds` in params. Will use it instead of argument\n",
      "  warnings.warn(\"Found `{}` in params. Will use it instead of argument\".format(alias))\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[5]\tvalid_0's auc: 0.750876\n",
      "[10]\tvalid_0's auc: 0.751726\n",
      "[15]\tvalid_0's auc: 0.753034\n",
      "[20]\tvalid_0's auc: 0.753851\n",
      "[25]\tvalid_0's auc: 0.754685\n",
      "[30]\tvalid_0's auc: 0.755478\n",
      "[35]\tvalid_0's auc: 0.756308\n",
      "[40]\tvalid_0's auc: 0.757042\n",
      "[45]\tvalid_0's auc: 0.757661\n",
      "[50]\tvalid_0's auc: 0.758194\n",
      "[55]\tvalid_0's auc: 0.758793\n",
      "[60]\tvalid_0's auc: 0.759392\n",
      "[65]\tvalid_0's auc: 0.759984\n",
      "[70]\tvalid_0's auc: 0.760448\n",
      "[75]\tvalid_0's auc: 0.76085\n",
      "[80]\tvalid_0's auc: 0.761266\n",
      "[85]\tvalid_0's auc: 0.76152\n",
      "[90]\tvalid_0's auc: 0.761876\n",
      "[95]\tvalid_0's auc: 0.76236\n",
      "[100]\tvalid_0's auc: 0.762723\n",
      "[105]\tvalid_0's auc: 0.76293\n",
      "[110]\tvalid_0's auc: 0.763206\n",
      "[115]\tvalid_0's auc: 0.763547\n",
      "[120]\tvalid_0's auc: 0.763749\n",
      "[125]\tvalid_0's auc: 0.764056\n",
      "[130]\tvalid_0's auc: 0.764264\n",
      "[135]\tvalid_0's auc: 0.764472\n",
      "[140]\tvalid_0's auc: 0.764677\n",
      "[145]\tvalid_0's auc: 0.764856\n",
      "[150]\tvalid_0's auc: 0.765087\n",
      "[155]\tvalid_0's auc: 0.765309\n",
      "[160]\tvalid_0's auc: 0.765584\n",
      "[165]\tvalid_0's auc: 0.765676\n",
      "[170]\tvalid_0's auc: 0.765921\n",
      "[175]\tvalid_0's auc: 0.766121\n",
      "[180]\tvalid_0's auc: 0.766336\n",
      "[185]\tvalid_0's auc: 0.766515\n",
      "[190]\tvalid_0's auc: 0.766791\n",
      "[195]\tvalid_0's auc: 0.766959\n",
      "[200]\tvalid_0's auc: 0.767168\n",
      "[205]\tvalid_0's auc: 0.767326\n",
      "[210]\tvalid_0's auc: 0.767533\n",
      "[215]\tvalid_0's auc: 0.76768\n",
      "[220]\tvalid_0's auc: 0.767828\n",
      "[225]\tvalid_0's auc: 0.767942\n",
      "[230]\tvalid_0's auc: 0.768043\n",
      "[235]\tvalid_0's auc: 0.768219\n",
      "[240]\tvalid_0's auc: 0.768369\n",
      "[245]\tvalid_0's auc: 0.768533\n",
      "[250]\tvalid_0's auc: 0.76869\n",
      "[255]\tvalid_0's auc: 0.768876\n",
      "[260]\tvalid_0's auc: 0.768964\n",
      "[265]\tvalid_0's auc: 0.769105\n",
      "[270]\tvalid_0's auc: 0.769316\n",
      "[275]\tvalid_0's auc: 0.769431\n",
      "[280]\tvalid_0's auc: 0.769522\n",
      "[285]\tvalid_0's auc: 0.769607\n",
      "[290]\tvalid_0's auc: 0.769733\n",
      "[295]\tvalid_0's auc: 0.769889\n",
      "[300]\tvalid_0's auc: 0.770009\n",
      "[305]\tvalid_0's auc: 0.77031\n",
      "[310]\tvalid_0's auc: 0.770448\n",
      "[315]\tvalid_0's auc: 0.770528\n",
      "[320]\tvalid_0's auc: 0.770612\n",
      "[325]\tvalid_0's auc: 0.77073\n",
      "[330]\tvalid_0's auc: 0.770813\n",
      "[335]\tvalid_0's auc: 0.77089\n",
      "[340]\tvalid_0's auc: 0.771133\n",
      "[345]\tvalid_0's auc: 0.771194\n",
      "[350]\tvalid_0's auc: 0.771239\n",
      "[355]\tvalid_0's auc: 0.771439\n",
      "[360]\tvalid_0's auc: 0.771617\n",
      "[365]\tvalid_0's auc: 0.771709\n",
      "[370]\tvalid_0's auc: 0.771765\n",
      "[375]\tvalid_0's auc: 0.771807\n",
      "[380]\tvalid_0's auc: 0.77199\n",
      "[385]\tvalid_0's auc: 0.772083\n",
      "[390]\tvalid_0's auc: 0.772125\n",
      "[395]\tvalid_0's auc: 0.772255\n",
      "[400]\tvalid_0's auc: 0.772425\n",
      "[405]\tvalid_0's auc: 0.772525\n",
      "[410]\tvalid_0's auc: 0.772681\n",
      "[415]\tvalid_0's auc: 0.772918\n",
      "[420]\tvalid_0's auc: 0.772996\n",
      "[425]\tvalid_0's auc: 0.773053\n",
      "[430]\tvalid_0's auc: 0.773229\n",
      "[435]\tvalid_0's auc: 0.773336\n",
      "[440]\tvalid_0's auc: 0.773464\n",
      "[445]\tvalid_0's auc: 0.773568\n",
      "[450]\tvalid_0's auc: 0.773606\n",
      "[455]\tvalid_0's auc: 0.773689\n",
      "[460]\tvalid_0's auc: 0.773735\n",
      "[465]\tvalid_0's auc: 0.773797\n",
      "[470]\tvalid_0's auc: 0.773908\n",
      "[475]\tvalid_0's auc: 0.774046\n",
      "[480]\tvalid_0's auc: 0.774092\n",
      "[485]\tvalid_0's auc: 0.774226\n",
      "[490]\tvalid_0's auc: 0.774334\n",
      "[495]\tvalid_0's auc: 0.774397\n",
      "[500]\tvalid_0's auc: 0.774552\n",
      "Wall time: 3min 46s\n"
     ]
    }
   ],
   "source": [
    "%time model_f1 = lgb.train(params, train_set=d_train_final,  valid_sets=watchlist_final,verbose_eval=5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "params = {\n",
    "        'objective': 'binary',\n",
    "        'metric': 'binary_logloss',\n",
    "        'boosting': 'dart',\n",
    "        'learning_rate': 0.1,\n",
    "        'verbose': 0,\n",
    "        'num_leaves': 108,\n",
    "        'bagging_fraction': 0.9,\n",
    "        'bagging_freq': 2,\n",
    "        'bagging_seed': 3,\n",
    "        'feature_fraction': 0.8,\n",
    "        'feature_fraction_seed': 2,\n",
    "        'max_bin': 256,\n",
    "        'max_depth': 30,\n",
    "        'num_rounds': 500,\n",
    "        'metric' : 'auc',\n",
    "        'using_missing' : False,\n",
    "        'sigmoid' : 1.0 ,\n",
    "        #'train_metric' : True\n",
    "    }"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "D:\\Users\\10100\\Anaconda3\\lib\\site-packages\\lightgbm\\engine.py:99: UserWarning: Found `num_rounds` in params. Will use it instead of argument\n",
      "  warnings.warn(\"Found `{}` in params. Will use it instead of argument\".format(alias))\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[5]\tvalid_0's auc: 0.750795\n",
      "[10]\tvalid_0's auc: 0.751752\n",
      "[15]\tvalid_0's auc: 0.752789\n",
      "[20]\tvalid_0's auc: 0.753526\n",
      "[25]\tvalid_0's auc: 0.754042\n",
      "[30]\tvalid_0's auc: 0.754695\n",
      "[35]\tvalid_0's auc: 0.755199\n",
      "[40]\tvalid_0's auc: 0.755668\n",
      "[45]\tvalid_0's auc: 0.756039\n",
      "[50]\tvalid_0's auc: 0.756323\n",
      "[55]\tvalid_0's auc: 0.756591\n",
      "[60]\tvalid_0's auc: 0.756831\n",
      "[65]\tvalid_0's auc: 0.757055\n",
      "[70]\tvalid_0's auc: 0.757298\n",
      "[75]\tvalid_0's auc: 0.757372\n",
      "[80]\tvalid_0's auc: 0.75753\n",
      "[85]\tvalid_0's auc: 0.757591\n",
      "[90]\tvalid_0's auc: 0.757698\n",
      "[95]\tvalid_0's auc: 0.757853\n",
      "[100]\tvalid_0's auc: 0.75798\n",
      "[105]\tvalid_0's auc: 0.757962\n",
      "[110]\tvalid_0's auc: 0.757995\n",
      "[115]\tvalid_0's auc: 0.758215\n",
      "[120]\tvalid_0's auc: 0.758417\n",
      "[125]\tvalid_0's auc: 0.758612\n",
      "[130]\tvalid_0's auc: 0.75873\n",
      "[135]\tvalid_0's auc: 0.758833\n",
      "[140]\tvalid_0's auc: 0.758841\n",
      "[145]\tvalid_0's auc: 0.758929\n",
      "[150]\tvalid_0's auc: 0.758916\n",
      "[155]\tvalid_0's auc: 0.759062\n",
      "[160]\tvalid_0's auc: 0.758987\n",
      "[165]\tvalid_0's auc: 0.759082\n",
      "[170]\tvalid_0's auc: 0.75936\n",
      "[175]\tvalid_0's auc: 0.759596\n",
      "[180]\tvalid_0's auc: 0.759568\n",
      "[185]\tvalid_0's auc: 0.759917\n",
      "[190]\tvalid_0's auc: 0.760127\n",
      "[195]\tvalid_0's auc: 0.760263\n",
      "[200]\tvalid_0's auc: 0.760392\n",
      "[205]\tvalid_0's auc: 0.76048\n",
      "[210]\tvalid_0's auc: 0.760483\n",
      "[215]\tvalid_0's auc: 0.760676\n",
      "[220]\tvalid_0's auc: 0.76081\n",
      "[225]\tvalid_0's auc: 0.760918\n",
      "[230]\tvalid_0's auc: 0.761023\n",
      "[235]\tvalid_0's auc: 0.761197\n",
      "[240]\tvalid_0's auc: 0.761486\n",
      "[245]\tvalid_0's auc: 0.761659\n",
      "[250]\tvalid_0's auc: 0.761853\n",
      "[255]\tvalid_0's auc: 0.762015\n",
      "[260]\tvalid_0's auc: 0.762266\n",
      "[265]\tvalid_0's auc: 0.762523\n",
      "[270]\tvalid_0's auc: 0.762691\n",
      "[275]\tvalid_0's auc: 0.762806\n",
      "[280]\tvalid_0's auc: 0.762929\n",
      "[285]\tvalid_0's auc: 0.763017\n",
      "[290]\tvalid_0's auc: 0.763365\n",
      "[295]\tvalid_0's auc: 0.763377\n",
      "[300]\tvalid_0's auc: 0.763546\n",
      "[305]\tvalid_0's auc: 0.763517\n",
      "[310]\tvalid_0's auc: 0.763564\n",
      "[315]\tvalid_0's auc: 0.763672\n",
      "[320]\tvalid_0's auc: 0.763822\n",
      "[325]\tvalid_0's auc: 0.763933\n",
      "[330]\tvalid_0's auc: 0.763959\n",
      "[335]\tvalid_0's auc: 0.763972\n",
      "[340]\tvalid_0's auc: 0.764041\n",
      "[345]\tvalid_0's auc: 0.764258\n",
      "[350]\tvalid_0's auc: 0.764345\n",
      "[355]\tvalid_0's auc: 0.764537\n",
      "[360]\tvalid_0's auc: 0.764746\n",
      "[365]\tvalid_0's auc: 0.764861\n",
      "[370]\tvalid_0's auc: 0.764912\n",
      "[375]\tvalid_0's auc: 0.765046\n",
      "[380]\tvalid_0's auc: 0.76506\n",
      "[385]\tvalid_0's auc: 0.765126\n",
      "[390]\tvalid_0's auc: 0.765377\n",
      "[395]\tvalid_0's auc: 0.765537\n",
      "[400]\tvalid_0's auc: 0.76577\n",
      "[405]\tvalid_0's auc: 0.765942\n",
      "[410]\tvalid_0's auc: 0.766109\n",
      "[415]\tvalid_0's auc: 0.766249\n",
      "[420]\tvalid_0's auc: 0.766269\n",
      "[425]\tvalid_0's auc: 0.76644\n",
      "[430]\tvalid_0's auc: 0.766558\n",
      "[435]\tvalid_0's auc: 0.766794\n",
      "[440]\tvalid_0's auc: 0.766952\n",
      "[445]\tvalid_0's auc: 0.767191\n",
      "[450]\tvalid_0's auc: 0.767361\n",
      "[455]\tvalid_0's auc: 0.767441\n",
      "[460]\tvalid_0's auc: 0.767527\n",
      "[465]\tvalid_0's auc: 0.767571\n",
      "[470]\tvalid_0's auc: 0.767568\n",
      "[475]\tvalid_0's auc: 0.767778\n",
      "[480]\tvalid_0's auc: 0.767796\n",
      "[485]\tvalid_0's auc: 0.767987\n",
      "[490]\tvalid_0's auc: 0.768186\n",
      "[495]\tvalid_0's auc: 0.768218\n",
      "[500]\tvalid_0's auc: 0.768378\n",
      "Wall time: 22min 54s\n"
     ]
    }
   ],
   "source": [
    "%time model_f2 = lgb.train(params, train_set=d_train_final,  valid_sets=watchlist_final, verbose_eval=5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Making predictions\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "print('Making predictions')\n",
    "\n",
    "p_test_1 = model_f1.predict(X_test)\n",
    "p_test_2 = model_f2.predict(X_test)\n",
    "p_test_avg = np.mean([p_test_1, p_test_2], axis = 0).round()\n",
    "\n",
    "p_train_1 = model_f1.predict(X_train)\n",
    "p_train_2 = model_f2.predict(X_train)\n",
    "p_train_avg = np.mean([p_train_1, p_train_2], axis = 0).round()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.713819745838\n"
     ]
    }
   ],
   "source": [
    "#模型评价\n",
    "from sklearn import metrics\n",
    "pre_rate = metrics.roc_auc_score(y_train,model_f1.predict(X_train).round())\n",
    "print(pre_rate)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.788392937011\n"
     ]
    }
   ],
   "source": [
    "pre_rate2 = metrics.roc_auc_score(y_train,model_f1.predict(X_train))\n",
    "print(pre_rate2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[1655851  617478]\n",
      " [ 780282 1814240]]\n",
      "[[407921 160089]\n",
      " [202254 446699]]\n"
     ]
    }
   ],
   "source": [
    "#模型评价\n",
    "from sklearn import metrics\n",
    "from scipy import interp \n",
    "cm_train = metrics.confusion_matrix(y_train,model_f1.predict(X_train).round())  #训练样本的混淆矩阵\n",
    "print(cm_train)\n",
    "cm_test = metrics.confusion_matrix(y_test,model_f1.predict(X_test).round())  #训练样本的混淆矩阵\n",
    "print(cm_test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[1531420  741909]\n",
      " [ 687479 1907043]]\n",
      "[[378455 189555]\n",
      " [177058 471895]]\n"
     ]
    }
   ],
   "source": [
    "#模型评价\n",
    "from sklearn import metrics\n",
    "from scipy import interp \n",
    "cm_train = metrics.confusion_matrix(y_train,model_f2.predict(X_train).round())  #训练样本的混淆矩阵\n",
    "print(cm_train)\n",
    "cm_test = metrics.confusion_matrix(y_test,model_f2.predict(X_test).round())  #训练样本的混淆矩阵\n",
    "print(cm_test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[1597118  676211]\n",
      " [ 733250 1861272]]\n",
      "[[394029 173981]\n",
      " [189379 459574]]\n"
     ]
    }
   ],
   "source": [
    "#模型评价\n",
    "from sklearn import metrics\n",
    "from scipy import interp \n",
    "cm_train = metrics.confusion_matrix(y_train,p_train_avg)  #训练样本的混淆矩阵\n",
    "print(cm_train)\n",
    "cm_test = metrics.confusion_matrix(y_test,p_test_avg)  #训练样本的混淆矩阵\n",
    "print(cm_test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXcAAAD8CAYAAACMwORRAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4wLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvpW3flQAAHiVJREFUeJzt3Xl8VeW97/HPj8yEMGRiSMIcZkEw\n4oBXtM7DwVurFn3ZquXW2qodrO2xt623tee2p/W0nlq9tpxa7XAUqT0H0eJQwemgDFEQQpjCmBAg\nCQkZybCzn/NHojeNgWxg77328H2/Xnmxh5Wd7yLJl4dnrbUfc84hIiKxZYDXAUREJPhU7iIiMUjl\nLiISg1TuIiIxSOUuIhKDVO4iIjFI5S4iEoNU7iIiMUjlLiISgxK9+sLZ2dlu7NixXn15EZGo9P77\n79c453L6286zch87dizFxcVefXkRkahkZvsC2U7TMiIiMUjlLiISg1TuIiIxSOUuIhKDVO4iIjGo\n33I3s9+ZWZWZlRzneTOzR82szMw2mdmc4McUEZGTEcjI/WngyhM8fxVQ2P1xJ/DE6ccSEZHT0e95\n7s65t81s7Ak2uQ74g+tar2+NmQ01s5HOuYNByigiElWcc7S0d9Lc7uNYeyetHX7afX7aOztp8/k5\ns2AoA5NDe5lRMF49Dyjvcb+i+7FPlLuZ3UnX6J7Ro0cH4UuLiIRWa0cnNU1t1Da3U9vczpGmrj/r\nWro/mjs4eqydhmM+Glo7aGz10dTmIynBGJSSSFpyAmlJCSQnDiA5YQBJCQP4+U2zoqLcrY/H+lx1\n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BdPb7Hj3f/fWwO9s+1rlAV\nEYlBkTwtIyIip0jlLiISg1TuIiIxSOUuIhKDVO4iIjFI5S4iEoNU7iIiMUjlLiISg/4bUm0YjqVr\nZe8AAAAASUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x201b5c89e10>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#roc曲线\n",
    "fpr, tpr, thresholds = metrics.roc_curve(y_test, p_test_1,pos_label = 1)##指定正例标签，pos_label = ###########在数之联的时候学到的，要制定正例 \n",
    "mean_fpr = np.linspace(0, 1, 100) \n",
    "mean_tpr = 0.0 #初始处为0 \n",
    "mean_tpr += interp(mean_fpr, fpr, tpr)          #对mean_tpr在mean_fpr处进行插值，通过scipy包调用interp()函数    \n",
    "                                 \n",
    "roc_auc = metrics.auc(fpr, tpr)    \n",
    "#画图，只需要plt.plot(fpr,tpr),变量roc_auc只是记录auc的值，通过auc()函数能计算出来    \n",
    "plt.plot(fpr, tpr, lw=1, label='ROC  (area = %0.3f)' % roc_auc) \n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  },
  "toc": {
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
